package com.demo.controller;

import com.demo.model.Student;
import com.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

@Controller
public class StudentController {

    //1.属性注入
//    @Autowired
//    private StudentService service;
//    public void sayHi() {
//            service.sayHi();
//    }

    //2.set 注入
//    private StudentService studentService;
//    @Autowired
//    public void setStudentService(StudentService studentService) {
//        this.studentService = studentService;
//    }
//    public void sayHi() {
//        //调用
//        studentService.sayHi();
//    }

    //3.构造方法注入  只加载一次
    /**
     * 1.可以注入一个不可变的对象
     *
     */

//    private StudentService studentService;
//
//    @Autowired
//
//    public StudentController(StudentService studentService) {
//        this.studentService = studentService;
//    }
//        public void sayHi() {
//        //调用
//        studentService.sayHi();
//    }

    private StudentService studentService;
    @Autowired

    public StudentController(StudentService studentService) {
        this.studentService = studentService;
    }
    public void getStudent() {
        System.out.println(studentService.student1());
    }
}
